<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-input
        placeholder="搜索订单"
        suffix-icon="el-icon-search"
        v-model="queryInfo.query"
      ></el-input>
      <el-table :data="orderList" border stripe>
        <el-table-column
          type="index"
          label="#"
          width="60"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          width="300"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="100"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款"
          width="100"
          align="center"
        >
          <template slot-scope="scoped">
            {{ scoped.row.order_pay }}
            <el-tag type="success" v-if="scoped.row.order_pay === '1'"
              >已付款</el-tag
            >
            <el-tag type="warning" v-else="">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
          width="100"
          align="center"
        >
          <template slot-scope="scoped">
            {{ scoped.row.is_send }}
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template v-slot="scoped">
            <el-button
              type="primary"
              icon="el-icon-edit"
              round
              size="small"
              @click="editOrder"
              ></el-button
            >
            <el-button type="success" icon="el-icon-setting" round size="small" @click="showProgressBox"
              ></el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <el-dialog
      title="修改收货地址"
      :visible.sync="editAddressFormVisible"
      width="50%"
      @close="editAddressFormClose"
    >
      <el-form
        :model="editAddressForm"
        :rules="editAddressFormRules"
        ref="editAddressFormRef"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="editAddressForm.address1"
            :options="cityData"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="物流状态"
      :visible.sync="showProgressBoxVisible"
      width="50%"
    >
      这是一段物流信息
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './cityData'

export default {
  data() {
    return {
        queryInfo: {
            query: '',
            pagenum: 1,
            pagesize: 10,
        },
        total: 0,
        orderList: [],
        editAddressFormVisible: false,
        //编辑地址表单
        editAddressForm:{
            address1: [],
            address2: ''
        },
        cityData: cityData,
        //编辑地址校验规则
        editAddressFormRules: {},
        showProgressBoxVisible: false,
    };
  },
  created() {
      this.getOrderList();
  },
  methods: {
      //获取订单列表
       async getOrderList(){
           const {data: res} = await this.$http.get("orders", {params: this.queryInfo});
           if(res.meta.status != 200) return this.$message.error("获取订单列表失败！");
            this.orderList = res.data.goods;
            this.total = res.data.total;
            this.$message.success("获取订单列表成功！");
      },
      handleSizeChange(size){
          this.queryInfo.pagesize = size;
          this.getOrderList();
      },
      handleCurrentChange(currPage){
          this.queryInfo.pagenum = currPage;
          this.getOrderList();
      },
      editOrder(){
          this.editAddressFormVisible = true;
      },
      editAddressFormClose(){
        console.log(this.$refs.editAddressFormRef);
        this.$refs.editAddressFormRef.resetFields();
      },
      //显示物流进度按钮
      async showProgressBox(){
        this.showProgressBoxVisible = true;
        const {data: res} = await this.$http.get("/kuaidi/804909574412544580");
        if(res.meta.status != 200) return this.$message.error("获取物流信息失败！");
        console.log(res.data);
        
      }
  },
};
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 15px;
}
.el-cascader{
  width: 100%;
}
</style>